package com.lw.servicebase.exception;

import com.lw.commonutil.result.Result;
import com.lw.commonutil.result.ResultCodeEnum;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        e.printStackTrace();
        return Result.build( null, ResultCodeEnum.SERVICE_ERROR );
    }
    //自定义异常
    @ResponseBody
    @ExceptionHandler(GuliException.class)
    public Result error(GuliException e){
        e.printStackTrace();
        return Result.build( e.getCode(),e.getMsg() );
    }
    //shiro特定异常
    @ResponseBody
    @ExceptionHandler(UnauthorizedException.class)
    public Result error(UnauthorizedException e){
        e.printStackTrace();
        return Result.build( null,ResultCodeEnum.PERMISSION );
    }
}
